package com.zxx.flowerstore.controller;

import com.zxx.flowerstore.entity.FlowerPoint;
import com.zxx.flowerstore.entity.enums.ResultEnum;
import com.zxx.flowerstore.service.UserPointService;
import com.zxx.flowerstore.utils.common.MyException;
import com.zxx.flowerstore.utils.common.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName UserPointController
 * @Author Admin
 * @Date 2021/4/3 7:48
 * @Description UserPointController
 * @Version 1.0
 */
@RestController
@RequestMapping("/userPoint")
@CrossOrigin
public class UserPointController {

    @Autowired
    private UserPointService userPointService;

    private static final Logger logger = LoggerFactory.getLogger(UserPointController.class);

    @PostMapping("/addUserPoint")
    @ResponseBody
    public Result addUserPoint(@RequestBody FlowerPoint flowerPoint) {
        try {
            return userPointService.addUserPoint(flowerPoint);
        } catch (MyException me) {
            logger.info(me.getMessage());
            return Result.error(ResultEnum.ERROR.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.error("添加收货地址:"+e.getMessage());
            return Result.error(ResultEnum.ERROR.getCode(), "添加收货地址失败");
        }
    }



}
